<?php
session_start();
if(!empty($_GET['id'])){
    $id = $_GET['id'];
    include 'conn.php';
    $sql = "SELECT title, body, level, user_id FROM article WHERE id = ?";
    $stmt = $conn->prepare($sql);

// 绑定参数并执行查询
    $stmt->bind_param("i", $id);
    $stmt->execute();

// 获取结果集
    $result = $stmt->get_result();
    $info = $result->fetch_assoc();
    if ($info['level'] == 0) {
        echo "<h1>" . $info['title'] . "</h1><br><p>" . $info['body'] . "</p>";
    }else if ($info['level'] == 1) {
        if(empty($_SESSION['id'])){
            echo "<script>alert('当前文章不存在或权限不足！')</script>";
        }else{
            echo "<h1>" . $info['title'] . "</h1><br><p>" . $info['body'] . "</p>";
        }
    }else{
        if($_SESSION['id']==$info['user_id'] or $_SESSION['level']==0){
            echo "<h1>" . $info['title'] . "</h1><br><p>" . $info['body'] . "</p>";
        }
        else{
            echo "<script>alert('当前文章不存在或权限不足')</script>";
        }
    }
    $stmt->close();
    $conn->close();

}